package cn.maszy.action.customer;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;

import net.sourceforge.stripes.action.SessionScope;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.model.customer.B_T_Ufp_ContractWord;
import cn.maszy.model.customer.B_T_Ufp_Customer;
import cn.maszy.service.customer.B_T_Ufp_ContractWordService;
import cn.maszy.service.customer.B_T_Ufp_CustomerService;

@SessionScope
public class CustomerAction extends BaseAction<B_T_Ufp_Customer> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2475349243064011153L;
	private B_T_Ufp_Customer b_T_Ufp_Customer;
	private B_T_Ufp_ContractWord b_T_Ufp_ContractWord;
	@Autowired
	private B_T_Ufp_CustomerService b_T_Ufp_CustomerService;
	@Autowired
	private B_T_Ufp_ContractWordService b_T_Ufp_ContractWordService;
	private String checkIds;
	private Pager<B_T_Ufp_ContractWord> Pagers;
	private String flag;
	/*********************class set/get****************************/
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public B_T_Ufp_Customer getB_T_Ufp_Customer() {
		return b_T_Ufp_Customer;
	}
	public void setB_T_Ufp_Customer(B_T_Ufp_Customer b_T_Ufp_Customer) {
		this.b_T_Ufp_Customer = b_T_Ufp_Customer;
	}
	public B_T_Ufp_ContractWord getB_T_Ufp_ContractWord() {
		return b_T_Ufp_ContractWord;
	}
	public void setB_T_Ufp_ContractWord(B_T_Ufp_ContractWord b_T_Ufp_ContractWord) {
		this.b_T_Ufp_ContractWord = b_T_Ufp_ContractWord;
	}
	public Pager<B_T_Ufp_ContractWord> getPagers() {
		return Pagers;
	}
	public void setPagers(Pager<B_T_Ufp_ContractWord> pagers) {
		Pagers = pagers;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 页面查询
	 * @return
	 * @throws Exception
	 */
	public String costomerList() throws Exception {
		pager = new Pager<B_T_Ufp_Customer>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_CustomerService.selectList(b_T_Ufp_Customer,pager);
		return SUCCESS;
	}
	/**
	 * 新增更新
	 * @return
	 * @throws Exception
	 */
	public String costomerUpdate() throws Exception {
		int i	=b_T_Ufp_CustomerService.update(b_T_Ufp_Customer,flag);
		if(i>0)
			//目前只有点击提交后关闭
			//return ajaxForwardSuccess(getText("msg.operation.success"), "adminList", "closeCurrent", "investment/adminList");
		//保存不关闭暂时没做
		return ajaxForwardSuccess(getText("msg.operation.success"), "CostomerList","", "closeCurrent", "costomer/CostomerList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 页面跳转
	 * @return
	 * @throws Exception
	 */
	public String update() throws Exception {
		return SUCCESS;
	}
	/**
	 * 删除一条数据
	 * @return
	 * @throws Exception
	 */
	public String costomerDel() throws Exception {
		int i=b_T_Ufp_CustomerService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "CostomerList","", "forward", "costomer/CostomerList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 查询一条数据
	 * @return
	 * @throws Exception
	 */
	public String costomerDetail() throws Exception {
		if(b_T_Ufp_Customer==null){
			b_T_Ufp_Customer=b_T_Ufp_CustomerService.selectOne("");
			b_T_Ufp_Customer.setUuid(UUID.randomUUID().toString());
			flag="1";
		}else{
			b_T_Ufp_Customer=b_T_Ufp_CustomerService.selectOne(b_T_Ufp_Customer.getUuid());
			Pagers = new Pager<B_T_Ufp_ContractWord>(pageNum, numPerPage,orderField,orderDirection);
			Pagers = b_T_Ufp_ContractWordService.selectList(b_T_Ufp_ContractWord,Pagers,b_T_Ufp_Customer.getUuid());
			flag="2";
		}
		return SUCCESS;
	}
	//用于商机管理跟单记录中的联系人查找带回
	public String costomerDetailSellfow() throws Exception{
		b_T_Ufp_Customer=b_T_Ufp_CustomerService.selectOne(b_T_Ufp_Customer.getUuid());
		Pagers = new Pager<B_T_Ufp_ContractWord>(pageNum, numPerPage,orderField,orderDirection);
		Pagers = b_T_Ufp_ContractWordService.selectListfow(b_T_Ufp_ContractWord,Pagers,b_T_Ufp_Customer.getUuid());
		flag="3";
		return SUCCESS;
	}
}
